class SnitchNade extends Nade;

var() globalconfig string CriticalMessage;
var() globalconfig string WarningMessage;

struct DoorSavedState
{
	var bool bHidden;
//    var bool bSealed;
//    var float WeldStrength;
//    var float Health;
};

simulated function HurtRadius( float DamageAmount, float DamageRadius, class<DamageType> DamageType, float Momentum, vector HitLocation )
{
	local actor Victim;
	local int i;
	local bool bAlreadyChecked, bWarn, bCrit;
    local array<KFDoorMover> DoorArray;
    local array<DoorSavedState> DoorStateArray;
    local KFDoorMover DoorMover;
    local DoorSavedState DoorState;
    local string txt;

	foreach CollidingActors (class 'Actor', Victim, DamageRadius, HitLocation)
    {
		if( (Victim != self) && (Hurtwall != Victim) && (Victim.Role == ROLE_Authority) && !Victim.IsA('FluidSurfaceInfo')
		 && ExtendedZCollision(Victim)==None )
		{
			if( (Instigator==None || Instigator.Health<=0) && KFPawn(Victim)!=None )
				Continue;

            if( Victim.IsA('KFDoorMover') )
            {
                DoorMover=KFDoorMover(Victim);

                if( DoorMover==None || DoorMover.bHidden )
                    continue;

		        for (i = 0; i < DoorArray.Length; i++)
				{
		        	if (DoorArray[i] == DoorMover)
					{
						bAlreadyChecked = true;
						break;
					}
				}

				if( bAlreadyChecked )
				{
					bAlreadyChecked = false;
					continue;
				}

                //log("A Door:"@DoorMover@", bHidden:"@DoorMover.bHidden@", Health:"@DoorMover.Health@", bSealed:"@DoorMover.bSealed@", Weld:"@DoorMover.WeldStrength);

				DoorArray[DoorArray.Length] = DoorMover;
                DoorState.bHidden = DoorMover.bHidden;
                //DoorState.bSealed = DoorMover.bSealed;
                //DoorState.WeldStrength = DoorMover.WeldStrength;
                //DoorState.Health = DoorMover.Health;
                DoorStateArray[DoorStateArray.Length] = DoorState;
            }
        }
    }

    Super.HurtRadius( DamageAmount, DamageRadius, DamageType, Momentum, HitLocation );
    
    for (i = 0; i < DoorArray.Length; i++)
    {
        DoorMover = DoorArray[i];
        DoorState = DoorStateArray[i];

        //log("S Door:"@DoorMover@", bHidden:"@DoorState.bHidden@", Health:"@DoorState.Health@", bSealed:"@DoorState.bSealed@", Weld:"@DoorState.WeldStrength);
        //log("B Door:"@DoorMover@", bHidden:"@DoorMover.bHidden@", Health:"@DoorMover.Health@", bSealed:"@DoorMover.bSealed@", Weld:"@DoorMover.WeldStrength);

        if(!DoorState.bHidden && !DoorMover.bHidden)
            bWarn = true; // door is still healthy

        if(!DoorState.bHidden && DoorMover.bHidden)
            bCrit = true; // broken
    }

    if (bCrit) {
        txt = Repl(default.CriticalMessage, "%PlayerName%", ""$Instigator.GetHumanReadableName()$"");
        Level.Game.Broadcast(None, txt);
    }
    else if (bWarn) {
        txt = Repl(default.WarningMessage, "%PlayerName%", ""$Instigator.GetHumanReadableName()$"");
        Level.Game.Broadcast(None, txt);
    }
}

defaultproperties
{
	CriticalMessage="Player %PlayerName% broke the door with a frag grenade!"
    WarningMessage="Player %PlayerName% threw a frag grenade at a door!"
}
